<?php session_start();

include 'php/conn.php';

$password = $_POST['password'];
$username = $_POST['login'];

$member = $username;
$_SESSION['member'] = $member;

$userExists = mysql_query("SELECT * FROM members WHERE username = '". $member ."' limit 1");
while($row = mysql_fetch_array($userExists))
  {
	  if($username == $row['username']) {$userCheck = true;}
	  if($password == $row['password']) {$passwordCheck = true;}
  }
  
	if (!$userCheck) {
		header('Location: index.html#retryL');
	} else if(!$passwordCheck) {
		header('Location: index.html#retryP'); 
	}
		

$result = mysql_query("SELECT * FROM members WHERE username = '". $member ."' limit 1");

while($row = mysql_fetch_array($result))
  {
  	$user_id = $row['id'];
  	$username = $row['username'];
	$hometown = $row['hometown'];
	$fighting = $row['fighting_style'];
	$fname = $row['fname'];
	$lname = $row['lname'];
  }
  $_SESSION['memberId']=$user_id;
$beers = mysql_query("SELECT * FROM beers_drank WHERE user_id = $user_id");

$beerTotal = mysql_num_rows($beers);
$lastBrewId = mysql_result($beers,$beerTotal-1);
while($row = mysql_fetch_array($beers))
	{
	  if($row['rating'] = 5) {$bestBrewId=$row['beer_id'];}
	 $rating = $row['rating'];
	}


$beerNames = mysql_query("SELECT beerName FROM beers");
while($row = mysql_fetch_array($beerNames)){
	if($row['beerID'] = $lastBrewId) $lastBrew=$row['beerName'];
	if($row['beerID'] = 7) $bestBrew = $row['beerName'];
}





?><!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<!--VIEWPORT META-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/>

<title>Beer Tixs Mobile App</title>

<!-- CSS stylesheets -->
    <link type="text/css" href="css/master.css" rel="stylesheet"/>
<!--WEBFONTS-->
	<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'/>
	<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,300' rel='stylesheet' type='text/css'/>    
<!--JAVASCRIPT-->
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
	<script type="text/javascript" src="js/scripts.js"></script>

</head>

<body>
	<!--SITE WRAPPER-->
	<div id="siteWrapper">
		<!--USER WRAPPER-->
		<div id="userWrapper">
			<div id="userIcon"><img src="images/icn_user.png" alt="beerTicks"/></div>
			<!--USERNAME-->
			<div id="userInfoWrapper">
				<div id="userName"><h3><?php echo $fname.' '.$lname ?></h3></div><!--/USERNAME-->
				<!--USER INFO-->
				<ul id="userInfo">
					<li class="infoTitle">Hometown:</li>
					<li class="info" id="hometownInfo"><?php echo $hometown ?></li>
					<li class="infoTitle">Fighting Style:</li>
					<li class="info" id="fightingInfo"><?php echo $fighting ?></li>
					<li class="infoTitle">Brews Ticked:</li>
					<li class="info" id="brewsInfo"><?php echo $beerTotal ?></li>
				</ul><!--/USER INFO-->
			</div>		
			<!--UBREW INFO-->
			<ul id="ubrewInfo">
				<li class="ubrewTitle">Good Beer:</li>
				<li class="ubrew" id="bestBrewInfo"><?php echo $bestBrew ?></li>
				<li class="ubrewTitle">Last Brew:</li>
				<li class="ubrew" id="lastBrewInfo"><?php echo $lastBrew ?></li>
			</ul><!--/UBREW INFO-->

			<!--RATING WRAPPER-->
			<div id="userRatingWrapper">
				<!--BREW RATING-->
				<div class="ratingWrapper">
					<div class="bestRating"><script type="text/javascript"> document.write(getStars(5));</script></div>
		            <div class="listRatingNumbers"> <?php echo $rating;?></div>
				</div>	
				<!--/BREW RATING-->  
			    
			    <!--BREW RATING-->
			    <div class="ratingWrapper">
					<div class="brewRating"><script type="text/javascript"> document.write(getStars(3));</script></div>
		            <div class="listRatingNumbers"> <?php echo $rating;?></div>
				</div>	
				<!--/BREW RATING-->
		    </div><!--/RATING WRAPPER-->

		    <!--BTN-->
		    <div id="btnWrapper">
			    <div id="yListBtn" class="listBtn"><a href="list.php"><img src="images/btn_yourList.png" alt="beerTicksBtn"/></a></div>       
			    <div id="mListBtn" class="listBtn"><a href="masterlist.php"><img src="images/btn_masterList.png" alt="beerTicksBtn"/></a></div>
			</div>    	
			    <!--/BTN-->       
		</div><!--/USER WRAPPER-->
		</div>
	</div><!--/SITE WRAPPER-->
</body>
</html>
